﻿#include "config.as"

function updateScoringUI(startingBracket:MovieClip, bluePoints:Number, redPoints:Number){
	
	adjustMovement(redPoints, bluePoints);
	
	if( (bluePoints == WINNING_SCORE) || (redPoints == WINNING_SCORE) ){
		gotoAndStop("End");
	}
	
	for(var i = 0; i < 	WINNING_SCORE; i++){
		var chitMovie:MovieClip;
		if(i < bluePoints){
			chitMovie = startingBracket.attachMovie("scoreChitBlue", BLUE_CHIT_NAME + i, 
													BLUE_CHIT_LAYER_START + i);			
		} else {			
			chitMovie = startingBracket.attachMovie("scoreChitEmpty", BLUE_CHIT_NAME + i, 
													BLUE_CHIT_LAYER_START + i);
		}
		chitMovie._x = (CHIT_X_DISTANCE * i) + CHIT_STARTING_DISTANCE;
		chitMovie._y = -CHIT_Y_DISTANCE;
	}		
	for(var i = 0; i < WINNING_SCORE; i++){
		var chitMovie:MovieClip;
		if(i < redPoints){
			chitMovie = startingBracket.attachMovie("scoreChitRed", RED_CHIT_NAME + i, 
										   RED_CHIT_LAYER_START + i);			
		} else {
			chitMovie = startingBracket.attachMovie("scoreChitEmpty", RED_CHIT_NAME + i, 
										   RED_CHIT_LAYER_START + i);			
		}
		chitMovie._x = (CHIT_X_DISTANCE * i) + CHIT_STARTING_DISTANCE;
		chitMovie._y = CHIT_Y_DISTANCE;
	}		
}

function adjustEndBracket(startingBracket:MovieClip){
	var endingDistance:Number = CHIT_STARTING_DISTANCE + (CHIT_X_DISTANCE * WINNING_SCORE);
	trace(endingDistance);
	trace(startingBracket._x);
	
	endBracket = startingBracket.attachMovie("scoreBracket", "endingBracket", 3);
	
	endBracket._x = endingDistance;	
	endBracket._rotation = 180;
}

function adjustMovement(redPoints:Number, bluePoints:Number){
	if(Math.abs(redPoints - bluePoints) >= SCRAMBLE_DIFFERENCE){
		maximumSpeed = SCRAMBLE_MAX_SPEED;
	} else {
		maximumSpeed = NORMAL_MAX_SPEED;
	}	
}